/*
 * cryptomfs - a macfuse implementation of cryptofs.
 * Copyright (C) 2008  Greg J. Hedlund
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
#import "CustomIconView.h"

@implementation CustomIconView

- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender

{
    NSPasteboard *pboard = [sender draggingPasteboard];

    if ( [[pboard types] containsObject:NSFilenamesPboardType] ) {

        NSArray *files = [pboard propertyListForType:NSFilenamesPboardType];

        int numberOfFiles = [files count];

        if ( numberOfFiles >= 1 ) {
			// save the first
			customIconPath = [[[files objectAtIndex:0] copy] retain];
		}
    }

    return YES;

}


- (void) setCustomIconPath:(NSString*)path
{
	NSImage * img = [[[NSImage alloc] initWithContentsOfFile:path] autorelease];
	if(img != nil) {
		[self setImage:img];
		customIconPath = [path copy];
	}
}

- (NSString*)customIconPath 
{
	if(customIconPath == nil)
		return [[NSBundle mainBundle] pathForResource:@"fs_mounted.icns" ofType:nil];
	else
		return customIconPath;
}

@end
